package dyyx;
import java.util.Date;

import org.apache.ibatis.jdbc.SQL;
import org.apache.ibatis.jdbc.SqlBuilder;

public class SqlBuilderTest {

	public static void main(String[] args) throws Exception {
		System.out.println("hello,SqlBuilderTest,"+new Date());
		
		String table = "t_user";
		
		SqlBuilder.BEGIN();  
		SqlBuilder.SELECT("*");  
		SqlBuilder.FROM(table);  
		
		System.out.println(SqlBuilder.SQL().toString());
		
		
		
		
		SqlBuilder.BEGIN();  
		SqlBuilder.INSERT_INTO(table);  
		SqlBuilder.VALUES("username", "#{username}");  
		SqlBuilder.VALUES("password", "#{password}");  
		SqlBuilder.VALUES("address", "#{address}");  
		SqlBuilder.VALUES("age", "#{age}");  
		SqlBuilder.VALUES("sex", "#{sex}"); 
		
		System.out.println(SqlBuilder.SQL().toString());

        
		SqlBuilder.BEGIN();  
		SqlBuilder.DELETE_FROM(table);  
		SqlBuilder.WHERE("username = #{username}");
		
		System.out.println(SqlBuilder.SQL().toString());

		
		SqlBuilder.BEGIN();  
		SqlBuilder.UPDATE(table);  
		SqlBuilder.SET("password = #{password}");  
		SqlBuilder.WHERE("username = #{username}");  
		System.out.println(SqlBuilder.SQL().toString());
		
		//
		System.out.println("******\n\n\n SQL build test");

		
		SQL sql = new SQL();
		sql.SELECT("*").FROM(table);
		System.out.println(sql.toString());
		

		sql = new SQL();
		sql.INSERT_INTO(table);
		sql.VALUES("username", "#{username}");  
		sql.VALUES("password", "#{password}");  
		sql.VALUES("address", "#{address}");  
		sql.VALUES("age", "#{age}");  
		sql.VALUES("sex", "#{sex}"); 
		
		System.out.println(sql.toString());
		
		
		sql = new SQL();
		sql.DELETE_FROM(table);  
		sql.WHERE("id = #{id}");
		System.out.println(sql.toString());

		
		sql = new SQL();
		sql.UPDATE(table);  
		sql.SET("password = #{password}");  
		sql.WHERE("id = #{id}");  
		System.out.println(sql.toString());
		
		
	}
}
